<?php
/**
 * Created by PhpStorm.
 * User: Kevin
 * Date: 2018/7/2
 * Time: 15:32
 */
namespace app\admin\controller;
use think\Request;
use think\Db;
class Email extends \app\admin\controller\Base
{
    protected $res = array(
        'index'   => array('css' => '2,3,4', 'js' => 'list'),
    );

    /**
     * index 首页数据
     * @return mixed
     */
    public function index(){
        $list = Db::table('up_about_us')
            ->field('a_id,a_service_email')
            ->select();
        $action = '/' . Request::instance()->controller() . '/' . Request::instance()->action();
        $this->assign ([
            'list'=>$list,
            'action'=>$action,
        ]);
        return $this->fetch();
    }

    /**
     * 修改
     * @return mixed
     */
    public function edit(){
        $id = input('id');
        if(request()->isAjax ()){
            extract(input());
            if($email == ''){
                return $this->api_error('邮箱不能为空', '14001');
            }
            $param = [
                'a_service_email'=>$email,
                'a_update_time'=>date('Y-m-d H:i:s')
            ];
            $res = Db::table('up_about_us')->where('a_id',$aid)->update($param);
            if ($res) {
                return $this->api_success("操作成功");
            } else {
                return $this->api_dbError("操作失败");
            }
        }
        $list = Db::table('up_about_us')
            ->where('a_id',$id)
            ->value('a_service_email');
        $this->assign ('id',$id);
        $this->assign ('data',$list);
        return $this->fetch('edit');
    }
}